import React from 'react'


class Cart extends React.Component {
    render(){
        let { cartItem,total } = this.props
        return (
            <div>
                <h1>Cart</h1>
                <ul>
                    {cartItem.map((item) => {
                        return (
                            <li key={item.id}>
                                <span>{item.title}</span>
                                --
                                <b>${item.price}</b>
                                --
                                <b>{item.quantity}</b>
                                &nbsp;
                                &nbsp;
                                &nbsp;
                                &nbsp;
                                <button>删除</button>                        
                            </li>
                        )              
                    })}
                </ul>
                {/* toFixed(2):保留小数点后面的2位 */}
                <h1>总价：{total.toFixed(2)}</h1>    
            </div>
        )
    }
}
export default Cart